package com.itstudio.myforumsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itstudio.myforumsystem.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper extends BaseMapper<User> {

@Select("select * from sys_user where id=#{id}")
    Integer find(Integer id);
@Insert("insert into sys_user(id,username,password,nickname,email,phone,address,avatar_url,sex,brief," +
        "nameofshcool,education,schooltime,birthday,role)" +
        "values (#{id},#{username},#{password},#{nickname},#{email},#{phone},#{address},#{avatarUrl},#{sex},#{brief},#{nameOfShcool},#{education},#{schoolTime},#{birthday},#{role})")
    void save(User user);


    @Select("select * from sys_user")
    List<User> findAll();
@Delete("delete from sys_user where id=#{id}")
    void deleteById(Integer id);
@Select("select * from sys_user where username=#{username} and password=#{password}")
    User findOne(Map<String, String> map);
@Select("select count(*) from sys_user where username like #{username}")
    Integer findName(@Param("username") String username);
@Select("select u.* from article a left join sys_user u on a.userid=u.id where a.id=#{articleId}")
    User findUserByArticle(Integer articleId);
    @Select("select count(*) count, u.* from sys_user u left join  article a on a.user = u.nickname where u.id = #{userId}  ")
    User allInforOfPersonal(Integer userId);

    @Select("select u.* from sys_user u order by id desc limit 5")
    List<User> limitFiveUser();
    @Select("select SUM(a.readnumber) from article a  left join sys_user u on a.userid = u.id where u.id = #{id}")
    Integer findReadNumber(Integer id);
    @Select("SELECT count(*) FROM collection c left join  sys_user u on u.id = c.userid where u.id = #{id}")
    Integer findCollectionNumber(Integer id);
}
